package admin

import (
	"MBGAdmin/models"
	"github.com/astaxie/beego/orm"
)

// 系统设置控制器
type SystemController struct {
	AuthController
}

// 系统设置首页
func (c *SystemController) Get() {
	var configs []*models.SystemConfigs
	o := orm.NewOrm()
	_, _ = o.QueryTable(models.SystemConfigs{}).All(&configs)
	for _, config := range configs {
		c.Data[config.Name] = config.Value
	}
	c.Display("admin/system/index.html")
}

// 系统设置保存
func (c *SystemController) Save() {
	data := [6]string{"site_name", "site_logo", "site_url", "site_keyword", "site_describe", "site_mobile"}
	o := orm.NewOrm().QueryTable(models.SystemConfigs{})
	for _, value := range data {
		_, _ = o.Filter("name", value).Update(orm.Params{
			"value": c.GetString(value),
		})
	}

	c.BaseResponse(0, "系统信息保存成功")
}
